home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / jedi.c < prev    next >
C/C++ Source or Header  |  2000-05-18  |  8KB  |  317 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #define JEDI_PLAYFIELD
  10.  
  11. #include "driver.h"
  12. #include "vidhrdw/generic.h"
  13.  
  14. unsigned char *jedi_backgroundram;
  15. size_t jedi_backgroundram_size;
  16. unsigned char *jedi_PIXIRAM;
  17. static unsigned int jedi_vscroll;
  18. static unsigned int jedi_hscroll;
  19. static unsigned int jedi_alpha_bank;
  20. static unsigned char *dirtybuffer2;
  21. static struct osd_bitmap *tmpbitmap2,*tmpbitmap3;
  22.  
  23. WRITE_HANDLER( jedi_vscroll_w ) {
  24.     jedi_vscroll = data | (offset << 8);
  25. }
  26.  
  27. WRITE_HANDLER( jedi_hscroll_w ) {
  28.     jedi_hscroll = data | (offset << 8);
  29. }
  30.  
  31. WRITE_HANDLER( jedi_alpha_banksel_w )
  32. {
  33.     if (jedi_alpha_bank != 2*(data & 0x80))
  34.     {
  35.         jedi_alpha_bank = 2*(data & 0x80);
  36.         memset(dirtybuffer,1,videoram_size);
  37.     }
  38. }
  39.  
  40.  
  41.  
  42. /* Color RAM format
  43.    Color RAM is 1024x12
  44.    RAM address: A0..A3 = Playfield color code
  45.                 A4..A7 = Motion object color code
  46.                 A8..A9 = Alphanumeric color code
  47.    RAM data:
  48.                 0..2 = Blue
  49.                 3..5 = Green
  50.                 6..8 = Blue
  51.                 9..11 = Intesnsity
  52.     Output resistor values:
  53.                bit 0 = 22K
  54.                bit 1 = 10K
  55.                bit 2 = 4.7K
  56. */
  57.  
  58.  
  59. WRITE_HANDLER( jedi_paletteram_w )
  60. {
  61.     int r,g,b;
  62.     int bits,intensity;
  63.     unsigned int color;
  64.  
  65.  
  66.     paletteram[offset] = data;
  67.     color = paletteram[offset & 0x3FF] | (paletteram[offset | 0x400] << 8);
  68.     intensity = (color >> 9) & 0x07;
  69.     bits = (color >> 6) & 0x07;
  70.     r = 5 * bits * intensity;
  71.     bits = (color >> 3) & 0x07;
  72.     g = 5 * bits * intensity;
  73.     bits = (color >> 0) & 0x07;
  74.     b = 5 * bits * intensity;
  75.  
  76.     palette_change_color (offset & 0x3ff,r,g,b);
  77. }
  78.  
  79.  
  80.  
  81. /***************************************************************************
  82.  
  83.   Start the video hardware emulation.
  84.  
  85. ***************************************************************************/
  86. int jedi_vh_start(void)
  87. {
  88.     if ((dirtybuffer = malloc(videoram_size)) == 0)
  89.     {
  90.         return 1;
  91.     }
  92.     memset(dirtybuffer,1,videoram_size);
  93.  
  94.     if ((tmpbitmap = osd_new_bitmap(Machine->drv->screen_width,Machine->drv->screen_height,8)) == 0)
  95.     {
  96.         free(dirtybuffer);
  97.         return 1;
  98.     }
  99.  
  100.     if ((dirtybuffer2 = malloc(jedi_backgroundram_size)) == 0)
  101.     {
  102.         osd_free_bitmap(tmpbitmap);
  103.         free(dirtybuffer);
  104.         return 1;
  105.     }
  106.     memset(dirtybuffer2,1,jedi_backgroundram_size);
  107.  
  108.     if ((tmpbitmap2 = osd_new_bitmap(Machine->drv->screen_width,Machine->drv->screen_height,8)) == 0)
  109.     {
  110.         osd_free_bitmap(tmpbitmap);
  111.         free(dirtybuffer);
  112.         free(dirtybuffer2);
  113.         return 1;
  114.     }
  115.  
  116.     /* the background area is 512x512 */
  117.     if ((tmpbitmap3 = osd_new_bitmap(512,512,8)) == 0)
  118.     {
  119.         osd_free_bitmap(tmpbitmap);
  120.         osd_free_bitmap(tmpbitmap2);
  121.         free(dirtybuffer);
  122.         free(dirtybuffer2);
  123.         return 1;
  124.     }
  125.  
  126.     return 0;
  127. }
  128.  
  129. /***************************************************************************
  130.  
  131.   Stop the video hardware emulation.
  132.  
  133. ***************************************************************************/
  134. void jedi_vh_stop(void)
  135. {
  136.     osd_free_bitmap(tmpbitmap);
  137.     osd_free_bitmap(tmpbitmap2);
  138.     osd_free_bitmap(tmpbitmap3);
  139.     free(dirtybuffer);
  140.     free(dirtybuffer2);
  141. }
  142.  
  143.  
  144.  
  145. WRITE_HANDLER( jedi_backgroundram_w )
  146. {
  147.     if (jedi_backgroundram[offset] != data)
  148.     {
  149.         dirtybuffer2[offset] = 1;
  150.  
  151.         jedi_backgroundram[offset] = data;
  152.     }
  153. }
  154.  
  155.  
  156.  
  157. /***************************************************************************
  158.  
  159.   Draw the game screen in the given osd_bitmap.
  160.   Do NOT call osd_update_display() from this function, it will be called by
  161.   the main emulation engine.
  162.  
  163. ***************************************************************************/
  164. void jedi_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  165. {
  166.     int offs;
  167.  
  168.  
  169.     if (palette_recalc())
  170.     {
  171.         memset(dirtybuffer,1,videoram_size);
  172.         memset(dirtybuffer2,1,jedi_backgroundram_size);
  173.     }
  174.  
  175.  
  176.     /* Return of the Jedi has a peculiar playfield/sprite priority system. That */
  177.     /* is, there is no priority system ;-) The color of the pixel which appears on */
  178.     /* screen depends on all three of the foreground, background and sprites. The */
  179.     /* 1024 colors palette is appropriately set up by the program to "emulate" a */
  180.     /* priority system, but it can also be used to display completely different */
  181.     /* colors (see the palette test in service mode) */
  182.  
  183.     /* foreground */
  184.     for (offs = videoram_size - 1;offs >= 0;offs--)
  185.     {
  186.         if (dirtybuffer[offs])
  187.         {
  188.             int sx,sy;
  189.  
  190.  
  191.             dirtybuffer[offs] = 0;
  192.  
  193.             sx = offs % 64;
  194.             sy = offs / 64;
  195.  
  196.             drawgfx(tmpbitmap,Machine->gfx[0],
  197.                     videoram[offs] + jedi_alpha_bank,
  198.                     0,
  199.                     0,0,
  200.                     8*sx,8*sy,
  201.                     &Machine->drv->visible_area,TRANSPARENCY_NONE_RAW,0);
  202.         }
  203.     }
  204.  
  205.  
  206.     /* background */
  207.     for (offs = jedi_backgroundram_size/2 - 1;offs >= 0;offs--)
  208.     {
  209.         if (dirtybuffer2[offs] != 0 || dirtybuffer2[offs + 0x400] != 0)
  210.         {
  211.             int sx,sy,b,c;
  212.  
  213.  
  214.             dirtybuffer2[offs] = dirtybuffer2[offs + 0x400] = 0;
  215.  
  216.             sx = offs % 32;
  217.             sy = offs / 32;
  218.             c = (jedi_backgroundram[offs] & 0xFF);
  219.             b = (jedi_backgroundram[offs + 0x400] & 0x0F);
  220.             c = c | ((b & 0x01) << 8);
  221.             c = c | ((b & 0x08) << 6);
  222.             c = c | ((b & 0x02) << 9);
  223.  
  224.             drawgfx(tmpbitmap3,Machine->gfx[1],
  225.                     c,
  226.                     0,
  227.                     b & 0x04,0,
  228.                     16*sx,16*sy,
  229.                     0,TRANSPARENCY_NONE_RAW,0);
  230.         }
  231.     }
  232.  
  233.  
  234.     /* Draw the sprites. Note that it is important to draw them exactly in this */
  235.     /* order, to have the correct priorities. */
  236.     fillbitmap(tmpbitmap2,0,&Machine->drv->visible_area);
  237.  
  238.     for (offs = 0;offs < 0x30;offs++)
  239.     {
  240.         int b,c;
  241.  
  242.  
  243.         b = ((spriteram[offs+0x40] & 0x02) >> 1);
  244.         b = b | ((spriteram[offs+0x40] & 0x40) >> 5);
  245.         b = b | (spriteram[offs+0x40] & 0x04);
  246.  
  247.         c = spriteram[offs] + (b * 256);
  248.         if (spriteram[offs+0x40] & 0x08) c |= 1;    /* double height */
  249.  
  250.         b = spriteram[offs+0x40] & 0x01;
  251.  
  252.         drawgfx(tmpbitmap2,Machine->gfx[2],
  253.                 c,
  254.                 0,
  255.                 (spriteram[offs+0x40] & 0x10),(spriteram[offs+0x40] & 0x20),
  256.                 (spriteram[offs+0x100]) | (b << 8),240-spriteram[offs+0x80],
  257.                 &Machine->drv->visible_area,TRANSPARENCY_PEN_RAW,0);
  258.  
  259.         if (spriteram[offs+0x40] & 0x08)    /* double height */
  260.             drawgfx(tmpbitmap2,Machine->gfx[2],
  261.                     c-1,
  262.                     0,
  263.                     (spriteram[offs+0x40] & 0x10),(spriteram[offs+0x40] & 0x20),
  264.                     (spriteram[offs+0x100]) | (b << 8),240-spriteram[offs+0x80]-16,
  265.                     &Machine->drv->visible_area,TRANSPARENCY_PEN_RAW,0);
  266.     }
  267.  
  268.  
  269.     /* compose the three layers */
  270.     {
  271.         int x,y;
  272.         UINT8 *s1,*s2,*s3;
  273.  
  274.  
  275.         if (bitmap->depth == 16)
  276.         {
  277.             for (y = 0;y < bitmap->height;y++)
  278.             {
  279.                 UINT16 *d;
  280.  
  281.                 d = (UINT16 *)bitmap->line[y];
  282.                 s1 = tmpbitmap->line[y];
  283.                 s2 = tmpbitmap2->line[y];
  284.                 s3 = tmpbitmap3->line[(y + jedi_vscroll) & 0x1ff];
  285.  
  286.                 for (x = 0;x < bitmap->width;x++)
  287.                 {
  288.                     *(d++) = Machine->pens[
  289.                             (*(s1++) << 8) |
  290.                             (*(s2++) << 4) |
  291.                             s3[(x + jedi_hscroll) & 0x1ff]];
  292.                 }
  293.             }
  294.         }
  295.         else
  296.         {
  297.             for (y = 0;y < bitmap->height;y++)
  298.             {
  299.                 UINT8 *d;
  300.  
  301.                 d = bitmap->line[y];
  302.                 s1 = tmpbitmap->line[y];
  303.                 s2 = tmpbitmap2->line[y];
  304.                 s3 = tmpbitmap3->line[(y + jedi_vscroll) & 0x1ff];
  305.  
  306.                 for (x = 0;x < bitmap->width;x++)
  307.                 {
  308.                     *(d++) = Machine->pens[
  309.                             (*(s1++) << 8) |
  310.                             (*(s2++) << 4) |
  311.                             s3[(x + jedi_hscroll) & 0x1ff]];
  312.                 }
  313.             }
  314.         }
  315.     }
  316. }
  317.